package error2

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func do() {
	defer fmt.Println("1")
	defer fmt.Println("2")
	fmt.Println("3")
	panic("aa")
	/*
		defer的作用：在函数结束时调用defer的语句
		调用顺序为倒序，即使有panic也会调用
	*/
}
func File_put_contents(filename string) {
	file, err := os.OpenFile(filename, os.O_EXCL|os.O_CREATE, 0666)
	if err != nil {
		panic(err)
	}
	defer file.Close()
	writer := bufio.NewWriter(file)
	defer writer.Flush()
	for i := 5; i < 10; i++ {
		writer.WriteString(strconv.Itoa(i))
	}
}
